package cn.iocoder.yudao.module.wine.controller.app.complaincomment;

import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;
import java.util.stream.Collectors;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.wine.controller.app.complaincomment.vo.*;
import cn.iocoder.yudao.module.wine.service.complaincomment.ComplainCommentService;

@Tag(name = "用户 APP - 投诉信息评价")
@RestController
@RequestMapping("/wine/complain-comment")
@Validated
public class AppComplainCommentController {

    @Resource
    private ComplainCommentService complainCommentService;

    @PostMapping("/create")
    @Operation(summary = "发布投诉信息评论")
    public CommonResult<Long> createComplainComment(@Valid @RequestBody AppComplainCommentSaveReqVO createReqVO) {
        return success(complainCommentService.createComplainComment(createReqVO));
    }

//    @PutMapping("/update")
//    @Operation(summary = "更新投诉信息评价")
//    public CommonResult<Boolean> updateComplainComment(@Valid @RequestBody AppComplainCommentSaveReqVO updateReqVO) {
//        complainCommentService.updateComplainComment(updateReqVO);
//        return success(true);
//    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除投诉信息评论")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteComplainComment(@RequestParam("id") Long id) {
        complainCommentService.deleteComplainComment(id);
        return success(true);
    }

//    @GetMapping("/page")
//    @Operation(summary = "获得投诉信息评价分页")
//    public CommonResult<PageResult<AppComplainCommentRespVO>> getComplainCommentPage(@Valid AppComplainCommentPageReqVO pageReqVO) {
//        PageResult<ComplainCommentDO> pageResult = complainCommentService.getComplainCommentPage(pageReqVO);
//        return success(BeanUtils.toBean(pageResult, AppComplainCommentRespVO.class));
//    }

    @GetMapping("/list")
    @Operation(summary = "获得投诉所有评论信息")
    public CommonResult<List<AppComplainCommentRespVO>> getComplainCommentList(@RequestParam("complainId") Long complainId) {
        List<AppComplainCommentRespVO> list = complainCommentService.getComplainCommentList(complainId);
        List<AppComplainCommentRespVO> collect = list.stream().peek(item -> {
            item.setAreaName(AreaUtils.format(item.getAreaId(), " "));
        }).collect(Collectors.toList());
        return success(collect);
    }
}
